package com.newbee.model.common;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * 通用的返回格式
 *
 * @author xjc
 * @Version 1.0-202409
 * @Since 2024-01-18 23:48
 */
@Data
public class CommonResponse<T> {

    private int httpStatus = HttpStatus.OK.value();

    private boolean success;

    private T data;

    private CommonResponse() {
    }

    public static <T> CommonResponse success() {
        CommonResponse resp = new CommonResponse();
        resp.setSuccess(true);
        return resp;
    }

    public static <T> CommonResponse success(T t) {
        CommonResponse resp = new CommonResponse();
        resp.setSuccess(true);
        resp.setData(t);
        return resp;
    }

    public static <T> CommonResponse fail(T t, HttpStatus httpStatus) {
        CommonResponse resp = new CommonResponse();
        resp.setSuccess(false);
        resp.setHttpStatus(httpStatus.value());
        resp.setData(t);
        return resp;
    }
}
